<!--Generate by Kevin's CodeBuilder -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
	<meta charset="UTF-8">
	<title>bui-ssm快速开发框架</title>

	<head th:include="source::header"></head>
	<style type="text/css">
		body {
			padding: 6px 6px;
		}

		#addRoot {
			text-decoration: underline;
			cursor: pointer;
		}
	</style>
</head>

<body>
	<div>
		<a id="addRoot">[(${Lang.org_addRoot})]</a>
	</div>
	<div style="padding-left: 30px">
		<ul id="tree"></ul>
	</div>
	<script type="text/javascript">
		var win, tree, rootId, $tree, height = 400;
		var reloadUl;
		var curdObj = {
			add: function (data) {
				$B.request({
					data: data,
					url: $B.getHttpHost(ctxPath) + "org/add",
					ok: function (message, data) {
						win.close();						
						queryTree(rootId);
					}
				});
			},
			update: function (data) {
				$B.request({
					data: data,
					url: $B.getHttpHost(ctxPath) + "org/update",
					ok: function (message, data) {
						win.close();
						queryTree(rootId);
					}
				});
			},
			closeWindow: function () {
				win.close();
			}
		};
		var title = "[(${Lang.org_windowTitle})]";//国际化语言
		//打开form.html
		function _openForm(prs, isUpdate) {
			var url = $B.getHttpHost(ctxPath) + "org/page/form";
			if (isUpdate) {
				url = url + "?id=" + prs.id;
			} else {
				url = url + "?pid=" + prs.id;
			}
			var opts = {
				dataType: 'html',
				title: title + "[" + prs.data.orgName + "]",
				width: 700,
				height: height,
				content: url
			};
			win = $B.window(opts);
		};

		window["toolMethods"] = {
			lineAddFn: function (prs) {
				var _this = this;
				reloadUl = this.parent().parent().parent().parent().parent();
				console.log(prs);
				_openForm(prs);
			},
			lineUpdateFn: function (prs) {
				var _this = this;
				reloadUl = this.parent().parent().parent().parent().parent();
				console.log(prs);
				_openForm(prs, true);
			},
			lineDeleteFn: function (prs) {
				var _this = this;
				reloadUl = this.parent().parent().parent().parent().parent();
				console.log(prs);
				$B.confirm({
					message: '[(${Lang.org_deleteConfirm})]',
					okFn: function () {
						$B.request({
							data: { idList: prs.id },
							url: $B.getHttpHost(ctxPath) + "org/delete",
							ok: function (message, data) {
								queryTree(rootId);
							}
						});
					}
				});
			}
		};
		function queryTree(pid) {
			if(reloadUl){//部分节点加载
				tree.reload(reloadUl,{gridid : "org",pid: pid});
			}else{//全树加载
				$B.request({
					data: { pid: pid ,gridid : "org"},
					url: $B.getHttpHost(ctxPath) + "org/query",
					ok: function (message, data) {
						createTree(data);
					}
				});
			}
		}
		function createTree(treeJson) {
			if (tree) {
				tree.clear();
			}
			if (treeJson.length === 0) {
				$tree.append("<li>[(${Lang.common_dataEmpty})]</li>");
				return;
			}
			tree = new $B.Tree($tree, {
				data: treeJson, //'数据'	
				toolbar: true,
				url:$B.getHttpHost(ctxPath) + "org/query?gridid=org",
				nodeParentIcon: 'fa-folder-empty', //父节点图标关闭状态
				nodeParentOpenIcon: 'fa-folder-open-empty', //打开状态图标
				leafNodeIcon: 'fa-doc', //子节点图标 
				checkbox: false,
				fontIconColor: '#5F52E3'
			});
		}
		$(function () {
			var treeJson = [(${ treeJson })];
			$tree = $("#tree");
			rootId = '[(${pid})]';
			createTree(treeJson);
			$("#addRoot").click(function () {
				reloadUl = undefined;
				var opts = {
					dataType: 'html',
					title: '[(${org_childmrg})]',
					width: 700,
					height: 400,
					content: $B.getHttpHost(ctxPath) + "org/page/form?pid=" + rootId
				};
				win = $B.window(opts);
			});
		});	
	</script>
</body>

</html>